package com.trkj.controller.hjj;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.trkj.pojo.StaffInformation;
import com.trkj.service.hjj.CreditCardDataService;
import com.trkj.vo.Result_AddRule_Result;
import com.trkj.vo.SloscarddateVo;

@Controller
public class CardDataListController {
	@Autowired
	private CreditCardDataService creditCardData;
	
	@RequestMapping("is_all_creditcard_data")
	@ResponseBody
	public Map findAllSol(int page,int rows){
		Page<JSONArray> pages = PageHelper.startPage(page, rows);
		creditCardData.findAllSol();
		Map map =new HashMap<>();
		map.put("total", pages.getTotal());
		map.put("rows", pages.getResult());
		return map;
	}
	
	//按照部门查数据列表
		@RequestMapping("is_to_findTimecardDataListBydNameandTime")
		@ResponseBody
		public Map findTimeByNameandTime(int page,int rows,String stainDate,String stainEndDate,String stainName){
			Page<JSONArray> pages = PageHelper.startPage(page, rows);
			creditCardData.findTimeByNameandTime(stainDate, stainEndDate, stainName);
			Map map =new HashMap<>();
			map.put("total", pages.getTotal());
			map.put("rows", pages.getResult());
			return map;
		}
	//按照部门查数据列表
	@RequestMapping("is_to_findTimecardDataListBydName")
	@ResponseBody
	public Map findTimecardDataListBydName(int page,int rows,String dName){
		Page<JSONArray> pages = PageHelper.startPage(page, rows);
		creditCardData.findTimecardDataListBydName(dName);
		Map map =new HashMap<>();
		map.put("total", pages.getTotal());
		map.put("rows", pages.getResult());
		return map;
	}
	@RequestMapping("update_card_data")
	@ResponseBody
	public Result_AddRule_Result updateCardData(HttpSession session){
		try {
			StaffInformation s =(StaffInformation) session.getAttribute("staff");
			System.out.println(s);
			boolean b =creditCardData.playCard(s.getStainId());
			return Result_AddRule_Result.SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return Result_AddRule_Result.failure(e.getMessage());
		}
	}
}
